/*
 * @Description: 
 * @Author: changqing
 * @Date: 2021-08-30 12:31:52
 * @LastEditTime: 2021-08-30 12:36:21
 * @LastEditors: changqing
 * @Usage: 
 */
var { timer, interval } = require('rxjs'); 
var {take,single} = require('rxjs/operators');
timer(0, 1000).pipe(
  take(10),
  single()
)
.subscribe({
  next: data => {
    console.log(data);
  },
  error: (err) => {
    console.log(err)
  }
});
// Sequence contains more than one element

timer(1000).pipe(
  take(5),
  single(data => data === 0)
).subscribe({
  next: data => {
    console.log(`${data}`);
  },
  error: (err) => {
    console.log(`${err}`)
  },
  complete: () => {
    console.log('single complete');
  }
});


timer(1000).pipe(
  take(5),
  single(data => data === 1)
).subscribe({
  next: data => {
    console.log(`single 範例 (5): ${data}`);
  },
  error: (err) => {
    console.log(`single 發生錯誤範例 (5): ${err}`)
  },
  complete: () => {
    console.log('single 範例結束 (5)');
  }
});